//自定义表单验证
$.extend($.fn.validatebox.defaults.rules, {
    selectValueRequired: {
        validator: function (value, param) {
            var cValue = $('#' + param[0]).combobox('getValue');
            //console.log(cValue);
            //console.log(cValue!='' && cValue!=null);
            if (cValue != '' && cValue != null) {
                return true;
            }
            return false;
        },
        message: "{1}"
    },
    changePass: {
        validator: function (value, param) {
            var pass = $(param[0]).passwordbox('getValue');
            if (pass != "" && value == "") {
                return false;
            }
            return true;
        },
        message: '{1}'
    },
    confirmPass: {
        validator: function (value, param) {
            var pass = $(param[0]).passwordbox('getValue');
            return value == pass;
        },
        message: '{1}'
    },
    username: {//用户名校验
        validator: function (value, param) {
            var reg = new RegExp(/^\w{4,16}$/);
            return reg.test(value);
        },
        message: '{0}'
    },
    password: {//密码校验
        validator: function (value, param) {
            var reg = new RegExp(/^\w{4,16}$/);
            return reg.test(value);
        },
        message: '{0}'
    },
    checkUsername: {//用户名校验
        validator: function (value, param) {
            var opts = $(this).validatebox('options');
            var checkFlag = true;
            if (value != "" && !opts.notValidate) {
                var checkFlag = rsdp.ajaxCheck({
                    url: param[0],
                    param: {
                        "username": value
                    }
                });
                /*$.ajax({
                 type : 'post',
                 async : false,
                 dataType:'json',
                 url : param[0],
                 data : {
                 "username" : value
                 },
                 success : function(data) {
                 if (data.code!=200) {
                 checkFlag=false;
                 }
                 },
                 error: function(XMLHttpRequest, textStatus, errorThrown) {
                 $.insdep.error(textStatus);
                 }
                 });*/
            }
            return checkFlag;
        },
        message: '{1}'
    },
    checkDmFl: {//代码分类校验
        validator: function (value, param) {
            var fl = $("#dicfl").textbox('getValue');
            var dm = $("#dicdm").textbox('getValue');
            var checkFlag = true;
            //console.log("fl:"+fl+"dm:"+dm+"mc:"+value);
            if (fl != "" && dm != "" && value != "") {
                checkFlag = rsdp.ajaxCheck({
                    url: param[0],
                    param: {
                        "fl": fl,
                        "dm": dm,
                        "mc": value,
                        "id": $("#hid_id") ? $("#hid_id").val() : ""
                    }
                });
                /*$.ajax({
                 type : 'post',
                 async : false,
                 dataType:'json',
                 url : param[0],
                 data : {
                 "fl" : fl,
                 "dm" : dm,
                 "mc" : value,
                 "id" : $("#hid_id")?$("#hid_id").val():""
                 },
                 success : function(data) {
                 if (data.code!=200) {
                 checkFlag=false;
                 }
                 },
                 error: function(XMLHttpRequest, textStatus, errorThrown) {
                 $.insdep.error(textStatus);
                 }
                 });*/
            }
            return checkFlag;
        },
        message: '{1}'
    },
    dmfl: {
        validator: function (value, param) {
            var reg = new RegExp(/^[A-Za-z0-9_]{1,100}|^[\u4e00-\u9fa5_]{1,50}$/);
            return reg.test(value);
        },
        message: '{0}'
    },
    regxp: {//正则表达式验证
        validator: function (value, param) {
            //console.log(param[0]);
            var reg = new RegExp(param[0]);
            //console.log(reg.test(value))
            return reg.test(value);
        },
        message: '{1}'
    },
    maxLen: {//字符长度校验
        validator: function (value, param) {
            var len = strlen(value);
            if (parseInt(param[0]) < len) {
                return false;
            }
            return true;
        },
        message: '{1}'
    },
    checkGsmc: {//账户校验
        validator: function (value, param) {
            var checkFlag = true;
            if (value != "") {
                checkFlag = rsdp.ajaxCheck({
                    url: param[0],
                    param: {
                        "gsmc": value,
                        "id": $("#hid_id") ? $("#hid_id").val() : ""
                    }
                });
                //console.log("checkGsmc:"+checkFlag);
            }
            return checkFlag;
        },
        message: '{1}'
    },
    checkZh: {//账户校验
        validator: function (value, param) {
            var checkFlag = true;
            if (value != "") {
                checkFlag = rsdp.ajaxCheck({
                    url: param[0],
                    param: {
                        "bh": value,
                        "id": $("#hid_id") ? $("#hid_id").val() : ""
                    }
                });
            }
            return checkFlag;
        },
        message: '{1}'
    },
    checkXgsmc: {//小公司名称校验
        validator: function (value, param) {
            var checkFlag = true;
            if (value != "") {
                var gsid = $("#sel_gs").combobox('getValue');
                checkFlag = rsdp.ajaxCheck({
                    url: param[0],
                    param: {
                        "xgsmc": value,
                        "gsid": gsid,
                        "id": $("#hid_id") ? $("#hid_id").val() : ""
                    }
                });
            }
            return checkFlag;
        },
        message: '{1}'
    },
    checkRyXgsmc:{//员工新增公司校验
        validator: function (value, param) {
            var checkFlag = true;
            var gsamc = $("#gsamc").textbox('getValue');
            var gsbmc = $("#gsbmc").textbox('getValue');
            
            if (gsamc != ""&&gsbmc != "") {
                checkFlag = rsdp.ajaxCheck({
                    url: param[0],
                    param: {
                        "gsamc": gsamc,
                        "gsbmc": gsbmc
                    }
                });
            }
            return checkFlag;
        },
        message: '{1}'
    },
    checkRyxm: {//姓名校验
        validator: function (value, param) {
            var checkFlag = true;
            if (value != "") {
                checkFlag = rsdp.ajaxCheck({
                    url: param[0],
                    param: {
                        "gsid": $("#sel_gs").combobox('getValue'),
                        "xgsid": $("#sel_xgs").combobox('getValue'),
                        "zjlx": $("#sel_zjlx").combobox('getValue'),
                        "sfzhm": $("#ry_zjhm").val(),
                        "ryzt": $("#sel_ryzt").val()==""?"1":$("#sel_ryzt").val(),
                        "xm": value,
                        "id": $("#hid_id") ? $("#hid_id").val() : ""
                    }
                });
            }
            return checkFlag;
        },
        message: '{1}'
    },
    checkExcel: {//excel文件校验
        validator: function (value, param) {
            /*var suffix = /\.[^\.]+/.exec(value);
             suffix = suffix.toString().toLowerCase();
             console.log(suffix);*/
            if (value.toString().lastIndexOf(".xls") != -1) {
                return true;
            }
            return false;
        },
        message: '{0}'
    },
    sfz: {//excel文件校验
        validator: function (value, param) {
        		var zjlx = $('#' + param[0]).combobox('getValue');
        		if(zjlx=='201'){
        			$(this).val(value.toUpperCase());
                return new IDValidator().isValid(value.toUpperCase());
        		}
            return true;
        },
        message: '{1}'
    }
});